<?php
// $Id$

/**
 * Controller_Mine 控制器
 */
class Controller_Mine extends Controller_Abstract
{

	/**
	 * 显示用户的个人界面，这个界面是自己看自己的时候的界面
	 *
	 * @return mixed
	 */
	function actionIndex()
	{
        //如果还没有登录，那么转到/user/login界面
		if(!in_array("member", Q::registry('app')->currentUserRoles())){
			return $this->_redirect(url("user/login"));
		}else{
		//如果已经登录
			$user = Q::registry("app")->currentUser();
			$id = $user['id'];
		    $this->_view['username'] = $user['name'];	
			
            //查看我关注的证券
            $query = "select sec.id, name, code, sec_sum.follow_cnt, view_cnt, press_cnt
			from sec_sum, sec, sec_follow
			where sec_sum.id = sec.id and sec_follow.user_id = $id and sec_follow.sec_id = sec.id
			order by follow_time desc";
			
			$res = DB::query($query);
			$rows = array();
			while($row = $res->fetch_assoc()){
				$rows[] = $row;
			}
			$this->_view['secs'] = $rows;
			
			//查看我报道的小新闻
			$query = "select press, id, press_time 
				from sec_press
				where user_id = $id
				order by view_time desc
				";
			$res = DB::query($query);
			$presses = array();
			while($row = $res->fetch_assoc()){
				$presses[] = $row;
			}
			$this->_view['ps'] = $presses;
		}
	}
}


